package com.mass.core.sys.file.controller;

import com.mass.core.sys.file.model.FileInfoTemp;
import com.mass.core.sys.file.service.FileInfoService;
import com.mass.core.utils.AjaxResponse;
import com.mass.core.framework.aop.LogAop;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import java.util.List;

/**
 * 文件信息控制器</p>
 *
 */
@Api("文件信息")
@RestController
@RequestMapping(value="/file/fileInfo")
public class FileInfoController {

    private static final Logger LOGGER = LoggerFactory.getLogger(FileInfoController.class);

    @Autowired
    private FileInfoService fileInfoService;

    /**
     * 获取文件列表
     * @param fileInfo 查询条件
     * @param pageIndex 页码
     * @param pageSize 页大小
     * @return
     */
    @ApiOperation(value = "文件管理", notes = "查询文件信息")
    @ApiImplicitParams({
    	@ApiImplicitParam(value = "查询条件", paramType = "query", required = false, dataType = "FileInfoTemp"),
    	@ApiImplicitParam(name = "pageIndex", value = "当前页", paramType = "query", required = true, dataType = "Integer"),
    	@ApiImplicitParam(name = "pageSize", value = "查询行", paramType = "query", required = true, dataType = "Integer")
    })
    @LogAop(menuName="文件详情管理",operationDesc="查询")
    @RequestMapping(value="/list", method = RequestMethod.GET)
    public AjaxResponse list(FileInfoTemp fileInfo, Integer pageIndex, Integer pageSize){
        List<FileInfoTemp> page = fileInfoService.selectPageList(fileInfo,pageIndex,pageSize);
        return AjaxResponse.success("ok",page);
    }

    /**
     * 获取文件详情
     * @param id 文件id
     * @return
     */
    @ApiOperation(value = "查询文件", notes = "根据文件Id查询文件")
    @ApiImplicitParam(name = "id", value = "文件id", paramType = "query", required = true, dataType = "Integer")
    @LogAop(menuName="文件详情管理",operationDesc="查询")
    @RequestMapping(value="/details", method = RequestMethod.GET)
    public AjaxResponse details(@RequestParam("id") Long id){
    	FileInfoTemp fileInfo = this.fileInfoService.getEntityById(id);
        return AjaxResponse.success("ok",fileInfo);
    }


    /**
     * 删除文件
     * @param id                文件信息ID
     * @return
     */
    @ApiOperation(value = "删除文件", notes = "根据文件Id删除")
    @ApiImplicitParam(name = "id", value = "文件id", paramType = "query", required = true, dataType = "Integer")
    @LogAop(menuName="文件详情管理",operationDesc="删除")
    @RequestMapping(value = "/deleteEntityById", method = RequestMethod.DELETE)
    public AjaxResponse deleteEntityById(@RequestParam(value = "id") Long id){
        try {
            boolean b = this.fileInfoService.deleteEntityById(id);
            return b ? AjaxResponse.success("ok",id) : AjaxResponse.error("error",id);
        }catch (Exception e){
            LOGGER.error("FileInfo deleteEntityById error!",e);
            return AjaxResponse.error("error",id);
        }
    }
}
